package com.hyt.it.ogt.pj.data.job;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hyt.it.ogt.pj.data.model.entity.kw.PushPj;
import com.hyt.it.ogt.pj.data.mq.PushPjDataProducer;
import com.hyt.it.ogt.pj.data.service.kw.IPushPjService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;

import lombok.extern.slf4j.Slf4j;

/**
 * 推送评卷数据定时任务
 *
 * @author liuqi
 * @date 2022-05-27
 */
@Component
@Slf4j
public class PushPjDataJob {

    @Resource
    private PushPjDataProducer producer;

    @Resource
    private IPushPjService iPushPjService;

    /**
     * 从kw库查出推送任务放进mq
     */
    @XxlJob("kwPushDataJob")
    public void kwPushDataJob() throws Exception {
        log.info("执行评卷数据推送");
        // 查询未推送的评卷
        List<PushPj> pushPjList = iPushPjService.getList();
        for (PushPj pushPj : pushPjList) {
            producer.sendMessage(pushPj);
            // 更新状态
            iPushPjService.updateStatus(pushPj.getId(), 1);
        }
        log.info("执行评卷数据推送成功");
        XxlJobHelper.log("执行推送评卷任务成功");
    }

}
